"""
@Author  : 康帅
@Time    : 2021/6/28 14:40
@Function: set集合处理相关数据优势
"""


def list_test():
    """
    使用list数据结构对比set集合
    :return:
    """
    some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n']

    duplicates = []
    for value in some_list:
        if some_list.count(value) > 1:
            if value not in duplicates:
                duplicates.append(value)

    print(duplicates)  # ['b', 'n']


def set_test():
    """
    使用set集合数据结构对比list
    :return:
    """
    some_list = ['a', 'b', 'c', 'b', 'd', 'm', 'n', 'n']
    duplicates = list(set([x for x in some_list if some_list.count(x) > 1]))
    print(duplicates)


def set_intersection():
    """
    set 交集
    :return:
    """
    valid = set(['yellow', 'red', 'blue', 'green', 'black'])
    input_set = set(['red', 'brown'])
    print(input_set.intersection(valid))


def set_difference():
    """
    set 差集
    :return:
    """
    valid = set(['yellow', 'red', 'blue', 'green', 'black'])
    input_set = set(['red', 'brown'])
    print(input_set.difference(valid))


if __name__ == '__main__':
    list_test()
    set_test()
    set_intersection()
    set_difference()
